package fun.linze.order.controller;

import fun.linze.order.bean.Order;
import fun.linze.order.properties.OrderProperties;
import fun.linze.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@RefreshScope  ///启用自动刷新Nacos配置
@RestController
public class OrderController {

    @Autowired
    OrderService orderService;


//    @Value("${order.timeout}")
//    String orderTimeout;
//    @Value("${order.auto-confirm}")
//    String orderAutoConfirm;
    @Autowired
    OrderProperties orderProperties;


    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId,
                             @RequestParam("productId") Long productId) {

        return orderService.createOrder(productId, userId);

    }

    ///获取配置
    @GetMapping("/config")
    public String getConfig() {
        return "order.timeout: " + orderProperties.getTimeout() + ", order.auto-confirm: " + orderProperties.getAutoConfirm();
    }
}
